﻿#include <iostream>
#include <cmath>

// 常量定义
const double A = 32.4; // 与路径特性相关的常数
const double n = 20;   // 路径特性指数
const double B = 20;   // 与频率相关的常数

// 枚举不同的计算功能类型
enum FunctionType {
	LocationVariabilityEffect = 0,  // 位置可变性效应
	FieldStrength = 1,              // 场强
	FreeSpaceLoss = 2,              // 自由空间损耗
	DiffractionLoss = 3,            // 衍射损耗
	TroposphericScatterLoss = 4,    // 对流层散射损耗
	ReflectionLoss = 5,             // 反射损耗
	LineOfSightPropagationLoss = 6  // 因视距传播损耗
};

// 计算位置可变性效应
double calculateLocationVariabilityEffect(double distance, double frequency) {
	double result = A + 10 * n * log10(distance) + B * log10(frequency);
	return result;
}

// 计算场强
double calculateFieldStrength(double distance, double frequency) {
	double result = 18.2 + 40 * log10(distance) + 20 * log10(frequency);
	return result;
}

// 计算自由空间损耗
double calculateFreeSpaceLoss(double distance, double frequency) {
	double result = A + 10 * n * log10(distance) + B * log10(frequency);
	return result;
}

// 计算衍射损耗
double calculateDiffractionLoss(double distance, double frequency) {
	double result = 6.9 + 20 * log10(distance) + 20 * log10(frequency);
	return result;
}

// 计算对流层散射损耗
double calculateTroposphericScatterLoss(double distance, double frequency) {
	double result = 4 + 20 * log10(distance) + 20 * log10(frequency);
	return result;
}

// 计算反射损耗
double calculateReflectionLoss(double distance, double frequency) {
	double result = 4 + 20 * log10(distance) + 20 * log10(frequency);
	return result;
}

// 计算因视距传播损耗
double calculateLineOfSightPropagationLoss(double distance, double frequency, double Fs, double Fro) {
	double loss = A + 10 * n * log10(distance) + B * log10(frequency) - Fs - Fro;
	return loss;
}

int main() {
	int choice;
	std::cout << "请选择要计算的功能：" << std::endl;
	std::cout << "0. 位置可变性效应" << std::endl;
	std::cout << "1. 场强" << std::endl;
	std::cout << "2. 自由空间损耗" << std::endl;
	std::cout << "3. 衍射损耗" << std::endl;
	std::cout << "4. 对流层散射损耗" << std::endl;
	std::cout << "5. 反射损耗" << std::endl;
	std::cout << "6. 因视距传播损耗" << std::endl;
	std::cin >> choice;

	double distance, frequency, Fs, Fro;
	std::cout << "请输入传输距离（千米）：" << std::endl;
	std::cin >> distance;
	std::cout << "请输入频率（GHz）：" << std::endl;
	std::cin >> frequency;

	// 如果选择了因视距传播损耗，则需要额外输入 Fs 和 Fro
	if (choice == LineOfSightPropagationLoss) {
		std::cout << "请输入 Fs（海水对地传播损耗）：" << std::endl;
		std::cin >> Fs;
		std::cout << "请输入 Fro（大气透明度和水蒸气对地传播损耗）：" << std::endl;
		std::cin >> Fro;
	}

	double result;
	switch (choice) {
	case LocationVariabilityEffect:
		result = calculateLocationVariabilityEffect(distance, frequency);
		break;
	case FieldStrength:
		result = calculateFieldStrength(distance, frequency);
		break;
	case FreeSpaceLoss:
		result = calculateFreeSpaceLoss(distance, frequency);
		break;
	case DiffractionLoss:
		result = calculateDiffractionLoss(distance, frequency);
		break;
	case TroposphericScatterLoss:
		result = calculateTroposphericScatterLoss(distance, frequency);
		break;
	case ReflectionLoss:
		result = calculateReflectionLoss(distance, frequency);
		break;
	case LineOfSightPropagationLoss:
		result = calculateLineOfSightPropagationLoss(distance, frequency, Fs, Fro);
		break;
	default:
		std::cerr << "无效的选择！" << std::endl;
		return 1;
	}

	std::cout << "结果：" << result << std::endl;

	return 0;
}
